#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#  File-Name:   replicationFile_rhymeAndReason.r   		       		
#  Date:        23/04/28                		
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
pkgs <- c('ggplot2','dplyr','tidyverse','estimatr','conflicted','cregg','Hmisc',
          'haven','magrittr','tidyr','texreg','qwraps2','xtable','gridExtra')
# Comment in below if packages need to be installed
# for (pkg in pkgs) install.packages(pkg, character.only = TRUE)
for (pkg in pkgs) library(pkg, character.only = TRUE)
conflict_prefer("filter", "dplyr")
conflict_prefer("select", "dplyr")
conflict_prefer("recode", "dplyr")
conflict_prefer("lag", "dplyr")

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Loading data ----
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
dataRhymeAndReason <- read.csv('data_rhymeAndReason.csv', stringsAsFactors=T) 
dataRhymeAndReasonExt <- read.csv('data_rhymeAndReasonExt.csv', 
  stringsAsFactors=T) 
dataRhymeAndReasonExt_withDropOuts <- 
  read.csv('data_rhymeAndReasonExt_withDropOuts.csv', stringsAsFactors=T) 

#_____________________________________________________________________________#
#_____________________________________________________________________________#
# 4. Results ----
#_____________________________________________________________________________#
# 4.1 Rebel effect ----
#_____________________________________________________________________________#
# Figure 1: ---- 
# AMCE on outcome measures feeling represented and every MP like this MP for 
# all attributes.
#_____________________________________________________________________________#
out <- dataRhymeAndReason %>% mutate(vignette=factor(vignette)) 
results <- rbind(
  cj(out,feel.represented ~ bill + outcome + margin + gender + party + 
       term + rebel + vignette + country + bill, id= ~ resid, estimate='amce') %>% 
    mutate(variable='Feeling represented'),
  cj(out,like.this.mp ~ bill + outcome + margin + gender + party + 
       term + rebel + vignette + country + bill, id= ~ resid, estimate='amce') %>% 
    mutate(variable='Every MP like this MP'))

pdf('figure1.pdf', height=3)
results %>% filter(feature!='country'&feature!='vignette') %>%
  mutate(
    baseline=ifelse(estimate==0,'Baseline','Effect'),
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=level,y=estimate,ymin=lower,ymax=upper,
    color=baseline,fill=baseline)) +
  facet_grid(~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(position=position_dodge(width=.6),size=.3,shape=21) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.6),
    linewidth=1,size=.3,shape=21) +
  coord_flip() + 
  scale_color_manual(values=c('gray','black')) + 
  scale_fill_manual(values=c('gray','black')) + 
  labs(x='',y='AMCE (Rebel)') +
  guides(fill=guide_legend(ncol=4)) +
  theme_bw() +
  theme(legend.position='none',
    axis.text.y=element_text(color=c('gray',rep('black',4),'gray','black',
    'gray','black','gray','black','gray','black','gray','black')))
dev.off()

#_____________________________________________________________________________#
# 4.2  Rebellion as cue for policy congruence ----
#_____________________________________________________________________________#
# Figure 2: ----
# Difference between total rebel effect tau(Rebel) and rebel effect when 
# respondents learn that the MP shares their policy positions, 
# tau(Rebel | Congruence), does not share their policy positions 
# tau(Rebel | No congruence), shares the public's policy positions, 
# tau(Rebel | Congruence), or does not share the public’s policy position
# (Rebel | No congruence).
#_____________________________________________________________________________#
out <- dataRhymeAndReason %>% 
  select(resid,rebel,vignette,bill,treatment,feel.represented,like.this.mp,
    country) %>% 
  gather(variable,value,feel.represented:like.this.mp) %>%
  mutate(treatment=factor(treatment, levels=c('Baseline',
    'Against voter-With public','With voter-Against public','Against voter',
    'Against public','With public','With voter')))

results <- rbind(
  out %>% filter(treatment=='Baseline'|treatment=='With voter') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','With voter')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentWith voter') %>%
    mutate(term=str_sub(term,21,-1)),
  out %>% filter(treatment=='Baseline'|treatment=='Against voter') %>% 
    mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline',
                                   'Against voter'),levels=c('Baseline','Against voter'))) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentAgainst voter') %>%
    mutate(term=str_sub(term,21,-1)),
  out %>% filter(treatment=='Baseline'|treatment=='With public') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','With public')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentWith public') %>%
    mutate(term=str_sub(term,21,-1)),
  out %>% filter(treatment=='Baseline'|treatment=='Against public') %>% 
    droplevels() %>% 
    mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline',
      'Against public'),levels=c('Baseline','Against public'))) %>%
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
      clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentAgainst public') %>%
    mutate(term=str_sub(term,21,-1)),
  out %>% filter(treatment=='Baseline'|treatment=='With voter'|
      treatment=='With voter-Against public') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','With voter')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
      clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentWith voter') %>%
    mutate(term=paste(str_sub(term,21,-1),' broadly defined',sep='')),
  out %>% filter(treatment=='Baseline'|treatment=='Against voter'|
      treatment=='Against voter-With public') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','Against voter')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
      clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentAgainst voter') %>%
    mutate(term=paste(str_sub(term,21,-1),' broadly defined',sep='')),
  out %>% filter(treatment=='Baseline'|treatment=='With public'|
      treatment=='Against voter-With public') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','With public')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
      clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentWith public') %>%
    mutate(term=paste(str_sub(term,21,-1),' broadly defined',sep='')),
  out %>% filter(treatment=='Baseline'|treatment=='Against public'|
      treatment=='With voter-Against public') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','Against public')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
      clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentAgainst public') %>%
    mutate(term=paste(str_sub(term,21,-1),' broadly defined',sep='')))

pdf('figure2.pdf', height=3)
results %>% filter(term=='With voter'|term=='With public'|term=='Against voter'|
    term=='Against public') %>%
  mutate(l2=estimate-1.6*std.error,u2=estimate+1.6*std.error,
    variable=ifelse(variable=='feel.represented'|
      variable=='feel.represented.baseline','Feel represented',
    'Every MP like this MP')) %>%
  ggplot(aes(x=term,y=estimate,ymin=conf.low,ymax=conf.high)) +
  facet_grid(~variable) +
  geom_pointrange(size=.3,shape=21) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),linewidth=1,size=.3,shape=21) +
  geom_hline(yintercept=0,color='gray') +
  coord_flip() + 
  scale_y_continuous(limits=c(-.17,.17)) +
  labs(y='Eliminated effect',x='') +
  theme_bw()
dev.off()

#_____________________________________________________________________________#
# 4.3 Rebels and valence ----
#_____________________________________________________________________________#
# Figure 3: ----
# Effect of rebellion on whether respondents attribute a character trait 
# to the MP (MP traits).
#_____________________________________________________________________________#
var.list <- c('independent','loyal.to.party','honest','strong.convictions',
  'defends.interest.voters','willing.to.compromise','untrustworthy',
  'selfish','disrespectful','decisive','irresponsible','cowardly',
  'unreliable','stupid')

results <- dataRhymeAndReason %>% 
  filter(vignette==5) %>%
  select(resid,feel.represented,like.this.mp,rebel,treatment,var.list,bill,
    country) %>%
  pivot_longer(cols=unlist(var.list),names_to='variable') %>% 
  group_by(variable) %>%
  do(tidy(lm_robust(value~rebel+bill+country,data=.))) 

pdf('figure3.pdf',height=3)
results %>% ungroup() %>%
  mutate(variable=factor(recode(variable,'independent'='Independent','honest'='Honest',
    'strong.convictions'='Strong personal convictions',
    'defends.interest.voters'='Defends interest of his/her voters',
    'willing.to.compromise'='Willing to compromise','loyal.to.party'='Loyal to party',
    'decisive'='Decisive','stupid'='Stupid',
    'cowardly'='Cowardly','disrespectful'='Disrespectful','irresponsible'='Irresponsible',
    'selfish'='Selfish','unreliable'='Unreliable','untrustworthy'='Untrustworthy'),
    levels=c('Stupid','Untrustworthy','Unreliable','Selfish','Irresponsible','Disrespectful',
      'Cowardly','Loyal to party','Decisive', 'Willing to compromise',
      'Defends interest of his/her voters','Strong personal convictions',
      'Honest','Independent'))) %>%
  filter(term=='rebelRebel') %>% 
  mutate(lower=conf.low,upper=conf.high,
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=variable,y=estimate,ymin=lower,ymax=upper)) +
  geom_pointrange(position=position_dodge(width=.5),fatten=.4,shape=23) +
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.5),
    linewidth=1,fatten=.4,shape=23) +
  geom_hline(yintercept=0,color='gray') +
  coord_flip() + 
  labs(y='Effect of rebellion on probability\n of attributing character trait',
    x='') +
  theme_bw() +
  theme(legend.position='none',axis.text.y=element_text(size=8),
        axis.title.x=element_text(size=8))
dev.off()

#_____________________________________________________________________________#
# 4.4 Diminishing rebel bias and valence effects ----
#_____________________________________________________________________________#
# Figure 4: ---- 
# AMCE on outcome measures feeling represented and every MP like this MP for 
# all attributes by vignette number.
#_____________________________________________________________________________#
out <- dataRhymeAndReason %>% 
  mutate(vignette=factor(vignette))

results <- rbind(
  cj(out,feel.represented ~ bill + outcome + margin + gender + party + 
       term + rebel + country + bill, id= ~resid, 
     by= ~vignette, estimate='amce') %>% mutate(variable='Feeling represented'),
  cj(out,like.this.mp ~ bill + outcome + margin + gender + party + 
       term + rebel + country + bill, id= ~resid, 
     by= ~vignette, estimate='amce') %>% mutate(variable='Every MP like this MP'))

pdf('figure4.pdf', height=5)
results %>% filter(!is.na(std.error)&feature!='country') %>%
  mutate(l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=level,y=estimate,ymin=lower,ymax=upper,color=vignette,fill=vignette)) +
  facet_grid(~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(position=position_dodge(width=.6),size=.3,shape=21) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.6),
    linewidth=1,size=.3,shape=21) +
  coord_flip() + 
  scale_color_manual(values=c('black','grey40','grey40','grey','grey')) + 
  scale_fill_manual(values=c('black','grey40','white','grey','white')) + 
  labs(x='',y='AMCE (Rebel)') +
  guides(fill=guide_legend(ncol=5,title='Vignette'),
         color=guide_legend(ncol=5,title='Vignette')) +
  theme_bw() +
  theme(legend.position='bottom')
dev.off()

#_____________________________________________________________________________#
# 5 Follow-Up Experiment ----
#_____________________________________________________________________________#
# Figure 5: ---- 
# AMCE of rebel attribute on outcome variables feeling represented and 
# be like this MP by reminder treatment.
#_____________________________________________________________________________#
out <- dataRhymeAndReasonExt %>% 
  mutate(reminder = factor(
    ifelse(baseline=='Baseline','Baseline',
    ifelse(treatment=='Cognitive involved'|
      (treatment=='Baseline/Distraction'&
      ((orderDistraction==3&(as.numeric(vignette)==3|as.numeric(vignette)==4))|
      (orderDistraction==4&as.numeric(vignette)>3))),'Reminder',NA)))) %>%
  filter(!is.na(reminder)) %>%
  mutate(reminderVignette=factor(paste(reminder,vignette)))

results <- rbind(
  cj(out,feelingRepresented~rebel, id= ~resid, by = ~reminderVignette, 
    estimate='amce') %>% mutate(variable='Feeling represented'),
  cj(out,likeThisMP~rebel, id= ~resid, by =  ~reminderVignette, 
    estimate='amce') %>% mutate(variable='Every MP like this MP')) %>% 
  filter(!is.na(feature)) %>%
  mutate(l2=estimate-1.6*std.error,u2=estimate+1.6*std.error,
    vignette=factor(str_sub(reminderVignette,-1,-1),levels=c('4','3','2','1')),
    reminder=str_sub(reminderVignette,1,-3))

pdf('figure5.pdf',height=3)
results %>% filter(level=='Rebelled') %>%
  ggplot(aes(x=vignette,y=estimate,ymin=lower,ymax=upper,
    color=reminder,fill=reminder)) +
  geom_pointrange(position=position_dodge(width=.3),fatten=.5,size=.5,shape=21) +
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.3),
    linewidth=1,fatten=.5,size=1,shape=21) +
  facet_grid(~variable) +
  coord_flip() +
  geom_hline(aes(yintercept=0),color='gray') +
  labs(x='Vignette',y='AMCE (Rebel)') +
  guides(fill=guide_legend(ncol=4)) +
  scale_color_manual(values=c('black','grey')) +
  scale_fill_manual(values=c('black','grey')) +
  theme_bw() +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#_____________________________________________________________________________#
# Figure 6: ----
# Effect of rebellion on whether respondents attribute a character trait to the 
# MP. Estimates taken from a regression of binary indicator whether a trait is 
# attributed on rebel status interacted with after which vignette those 
# associations were elicited.
#_____________________________________________________________________________#
varList <- c('independent','loyalToParty','honest','strongConvictions',
  'defendsInterestVoters','willingToCompromise','untrustworthy',
  'selfish','disrespectful','decisive','irresponsible','cowardly',
  'unreliable','stupid')

results <- dataRhymeAndReasonExt %>% 
  filter(treatment=='Characteristics'|
    (treatment!='Characteristics'&vignette=='4')) %>%
  select(resid,feelingRepresented,likeThisMP,rebel,treatment,all_of(varList),
     vignette,baseline) %>%
  pivot_longer(cols=unlist(varList),names_to='variable') %>% 
  group_by(variable,vignette) %>%
  do(tidy(lm_robust(value~rebel,clusters=resid,data=.))) 

pdf('figure6.pdf',height=5)
results %>% ungroup() %>%
  mutate(variable=factor(recode(variable,'independent'='Independent',
    'honest'='Honest','strongConvictions'='Strong personal convictions',
    'defendsInterestVoters'='Defends interest of his/her voters',
    'willingToCompromise'='Willing to compromise',
    'loyalToParty'='Loyal to party','decisive'='Decisive','stupid'='Stupid',
    'cowardly'='Cowardly','disrespectful'='Disrespectful',
    'irresponsible'='Irresponsible','selfish'='Selfish',
    'unreliable'='Unreliable','untrustworthy'='Untrustworthy'),
    levels=c('Stupid','Untrustworthy','Unreliable','Selfish','Irresponsible',
    'Disrespectful','Cowardly','Decisive','Loyal to party',
    'Willing to compromise','Defends interest of his/her voters',
    'Strong personal convictions','Honest','Independent'))) %>% 
  filter(term=='rebelRebelled') %>% 
  mutate(estimate=100*estimate,lower=100*conf.low,upper=100*conf.high,
    l2=estimate-1.6*100*std.error,u2=estimate+1.6*100*std.error,
    vignette=as.factor(vignette)) %>%
  ggplot(aes(x=variable,y=estimate,ymin=lower,ymax=upper,
    color=vignette,fill=vignette)) +
  geom_pointrange(position=position_dodge(width=.75),size=.3,shape=21) +
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.75),
    linewidth=1,size=.3,shape=21) +
  geom_hline(yintercept=0,color='gray') +
  coord_flip() + 
  scale_color_manual(values=c('black','grey40','grey40','grey')) + 
  scale_fill_manual(values=c('black','grey40','white','grey')) +
  guides(fill=guide_legend(ncol=4,title='Vignette'),
    color=guide_legend(ncol=4,title='Vignette')) +
  labs(y='Effect of rebellion on percentage attributed to MP',x='') +
  theme_bw() +
  theme(legend.position='bottom',axis.text.y = element_text(size=10),
    axis.title.x = element_text(size=10))
dev.off()

#_____________________________________________________________________________#
# B Experimental design appendix ----
#_____________________________________________________________________________#
# B.3 Main experiment ----
#_____________________________________________________________________________#
# B.3.2 Manipulation checks and data quality ----
#_____________________________________________________________________________#
# Figure B.1: ----
# Average duration on vignette screen by vignette number for first experiment. 
#_____________________________________________________________________________#
pdf('figureB1.pdf',height=3)
dataRhymeAndReason %>% filter(timing<600) %>%
  group_by(vignette,country) %>%
  summarise(mean=mean(timing),lower=quantile(timing,.025),
    upper=quantile(timing,.975)) %>%
  ggplot(aes(y=mean,ymin=lower,ymax=upper,x=vignette)) + 
  facet_grid(~country) + 
  geom_pointrange() +
  scale_y_continuous(breaks=c(0,25,50,75,100,150),
    labels=c(0,25,50,75,100,150)) +
  labs(x='Vignette number',y='Time on vignette in seconds\n(omitting > 10min)') +
  theme_bw() +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#_____________________________________________________________________________#
# Figure B.2: ----
# Effect of receiving the With voter treatment (vs the Against voter treatment)
# on outcome measure by rebel status. Estimates obtained from a regression of 
# outcome measures on an indicator of the two treatments run separately by rebel 
# status.
#_____________________________________________________________________________#
r <- dataRhymeAndReason %>%
  filter(treatment=='With voter'|treatment=='Against voter') %>%
  droplevels() %>%
  pivot_longer(cols=c(like.this.mp,feel.represented)) %>% 
  group_by(name,rebel) %>%
  do(lm_robust(value~treatment,clusters=resid,data=.) %>% tidy()) 

pdf('figureB2.pdf', height=2)
r %>% filter(term=='treatmentWith voter') %>%
  mutate(
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error,
    name=factor(recode(name,'feel.represented'='Feeling represented',
                       'like.this.mp'='Every MP like this MP'))) %>%
  ggplot(aes(x=rebel,y=estimate,ymin=conf.low,ymax=conf.high)) +
  facet_grid(~name) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(fatten=.5,shape=21) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),fatten=.5,linewidth=1,shape=21) +
  coord_flip() + 
  labs(x='',y='AMCE (Rebel)') +
  guides(fill=guide_legend(ncol=4)) +
  theme_bw() +
  theme(legend.position='none')
dev.off()

#_____________________________________________________________________________#
# B.3.4 Treatment balance ----
#_____________________________________________________________________________#
# Table B.2: ----
# Social demographics and political positions by treatments in the main 
# experiment
#_____________________________________________________________________________#
summary <-
  list(
    "Age" = list(
      "mean (sd)" = ~ mean_sd(age),
      "min" = ~ min(age),
      "max" = ~ max(age)),
    "genderRespondent" = list(
      "Male" = ~ n_perc(genderRespondent=='Male'),
      "Female" = ~ n_perc(genderRespondent=='Female')),
    "Education" = list(
      'Primary education' = ~ n_perc(education==1),
      'Lower secondary education' = ~ n_perc(education==2),
      'Upper secondary education' = ~ n_perc(education==3),
      'Post-secondary non-tertiary educ'  = ~ n_perc(education==4),
      "Bachelor's or equivalent level"  = ~ n_perc(education==5),
      "Master's or equivalent level" = ~ n_perc(education==6),
      'Doctoral or equivalent level'= ~ n_perc(education==7)),
    "Size of locality" = list(
      'Big locality' = ~ n_perc(urban_rural==1),
      'Medium-sized locality' = ~ n_perc(urban_rural==2),
      'Small locality' = ~ n_perc(urban_rural==3)),
    "Social spending and taxes" = list(
      "Increase social spending" = ~ n_perc(social_pos==1,na_rm=T),
      "Decrease social spending" = ~ n_perc(social_pos==2,na_rm=T)),
    "Competence of the EU" = list(
      "Increase EU competencies" = ~ n_perc(eu1_pos==1,na_rm=T),
      "Decrease EU competencies" = ~ n_perc(eu1_pos==2,na_rm=T)),
    "Ties to EU" = list(
      "Strengthen ties to the EU" = ~ n_perc(eu2_pos==1,na_rm=T),
      "Weaken ties to the EU" = ~ n_perc(eu2_pos==2,na_rm=T)),
    "Immigration" = list(
      "Make it easier to immigrate" = ~ n_perc(immigration_pos==1,na_rm=T),
      "Make it harder to immigrate" = ~ n_perc(immigration_pos==2,na_rm=T)),
    "Climate policy" = list(
      "Establish new environ regs" = ~ n_perc(climate_pos==1,na_rm=T),
      "Remove existing environ regs" = ~ n_perc(climate_pos==2,na_rm=T)))

o <- dataRhymeAndReason %>%
  select(age,genderRespondent,education,urban_rural,social_pos,eu1_pos,eu2_pos,
    immigration_pos,climate_pos,treatment) %>%
  mutate(treatment=factor(treatment,
    levels=c("Baseline","Against voter-With public",
      "With voter-Against public","Against voter",
      "Against public","With public","With voter"))) %>%
  distinct() 

c <- c(
  "\\textbf{Age}","","",
  "\\textbf{Gender}","",
  "\\textbf{Education}","","","","","","",
  "\\textbf{Size of locality}","","",
  "\\textbf{Social spending}","",
  "\\textbf{Competencies of EU}","",
  "\\textbf{Ties to EU}","",
  "\\textbf{Immigration}","",
  "\\textbf{Climate policy}","")

s <- summary_table(group_by(o,treatment),summary) %>%
  data.frame()
n <- o %>% group_by(treatment) %>% summarise(N=n()) %>% pull(N)
t <- rbind(c("","",paste("(N=",n,")",sep='')),cbind(c,row.names(s),s))
p <- xtable(t)
names(p) <- c("","",
  "Baseline",
  "Against voter-With public",
  "With voter-Against public",
  "Against voter", 
  "Against public",      
  "With public",
  "With voter")

print(xtable(p,type='latex',
  align="rrllllllll"),
  file='tableB2.tex',include.rownames=F,floating=F,
  sanitize.text.function= function(x){x})
  
#_____________________________________________________________________________#
# B.4 Follow-up experiment ----
#_____________________________________________________________________________#
# Table B.3: ----
# Social demographics and political positions across treatments in the follow-up 
# experiment
#_____________________________________________________________________________#
summary <-
  list(
    "Age" = list(
      "mean (sd)" = ~ mean_sd(age[age>=18&!is.na(age)]),
      "min" = ~ min(age[age>=18&!is.na(age)]),
      "max" = ~ max(age[age>=18&!is.na(age)])),
    "Gender" = list(
      "Male" = ~ n_perc(gender=='Male',na_rm=T),
      "Female" = ~ n_perc(gender=='Female',na_rm=T),
      "Neither" = ~ n_perc(gender=='Neither',na_rm=T)),
    "Education" = list(
      "No schooling" = ~ n_perc(edu=='I have not completed any educational training or studies.',na_rm=T),
      "Primary school" = ~ n_perc(edu=='Primary school',na_rm=T),
      "9 years of schooling" = ~ n_perc(edu=='Comprehensive school, grammar school, secondary modern school (9 years of schooling without pre-school education)',na_rm=T),
      "11 years of schooling" = ~ n_perc(edu=='Comprehensive school, grammar school, secondary modern school (at least 11 years of schooling without pre-school education), further education (FE) institutions, school sixth form, sixth form college',na_rm=T),
      "Access to higher education"  = ~ n_perc(edu=='Access to Higher Education (HE Access) programme',na_rm=T),
      "Finished higher education" = ~ n_perc(edu=='Higher education (HE) institutions, university and similar education',na_rm=T),
      'Doctoral degree'= ~ n_perc(edu=='Doctoral degree',na_rm=T)),
    "Size of locality" = list(
      "Less than 2,000 inhabitants" = ~ n_perc(urban_rural=='Less than 2,000 inhabitants',na_rm=T),
      "2,000 to less than 5,000" = ~ n_perc(urban_rural=='2,000 to less than 5,000 inhabitants',na_rm=T),
      "5,000 to less than 20,000" = ~ n_perc(urban_rural=='5,000 to less than 20,000 inhabitants',na_rm=T),
      "20,000 to less than 100,000" = ~ n_perc(urban_rural=='20,000 to less than 100,000 inhabitants',na_rm=T),
      "100,000 to less than 1 million"  = ~ n_perc(urban_rural=='100,000 to less than 1 million inhabitants',na_rm=T),
      "1 million or more" = ~ n_perc(urban_rural=='1 million inhabitants and more',na_rm=T)),
    "Social spending" = list(
      "Increase social spending" = ~ n_perc(positionSocialSpending==4,na_rm=T),
      "Decrease social spending" = ~ n_perc(positionSocialSpending==2,na_rm=T)),
    "Ties to EU" = list(
      "Strengthen ties to the EU" = ~ n_perc(positionTiesEU==8,na_rm=T),
      "Weaken ties to the EU" = ~ n_perc(positionTiesEU==9,na_rm=T)),
    "Immigration" = list(
      "Make it easier to immigrate" = ~ n_perc(positionImmigration==5,na_rm=T),
      "Make it harder to immigrate" = ~ n_perc(positionImmigration==6,na_rm=T)),
    "Climate policy" = list(
      "Establish new environ regs" = ~ n_perc(positionClimate==3,na_rm=T),
      "Remove existing environ regs" = ~ n_perc(positionClimate==7,na_rm=T)))

o <- dataRhymeAndReasonExt %>% 
  select(age,gender,edu,urban_rural,positionSocialSpending:positionClimate,
    treatment,resid) %>% 
  mutate(treatment=factor(treatment,levels=c('Baseline/Distraction',
    'Alternative outcome','Characteristics','Cognitive involved',
    'Paired vignette first'))) %>%
  distinct()  

c <- c(
  "\\textbf{Age}","","",
  "\\textbf{Gender}","","",
  "\\textbf{Education}","","","","","","",
  "\\textbf{Size of locality}","","","","","",
  "\\textbf{Social spending}","",
  "\\textbf{Ties to EU}","",
  "\\textbf{Immigration}","",
  "\\textbf{Climate policy}","")

s <- summary_table(group_by(o,treatment),summary) %>%
  data.frame()
n <- o %>% group_by(treatment) %>% summarise(N=n()) %>% pull(N)
t <- rbind(c("","",paste("(N=",n,")",sep='')),cbind(c,row.names(s),s))
p <- xtable(t)
names(p) <- c("","",
              "Baseline/Distraction",
              "Alternative outcome",
              "Characteristics",
              "Cognitive involved", 
              "Paired vignette first")

print(xtable(p,type='latex',
             align="rrllllll"),
      file='tableB3.tex',include.rownames=F,floating=F,
      sanitize.text.function= function(x){x})

#_____________________________________________________________________________#
# Table B.4: ----
# Social demographics and political positions for respondents who dropped out 
# and those who finished the follow-up experiment. All of the drop-outs answered 
# the age and gender questions (right in the beginning of the survey) but only 
# 143 and 142 of them made it to the remaining questions about demographics and 
# political attitudes. We show p-values from a test over difference in means 
# (t-test for age) or over the contingency tables of the other variables (chi^2)
#_____________________________________________________________________________#
o <- dataRhymeAndReasonExt_withDropOuts %>% 
  select(age,gender,edu,urban_rural,positionSocialSpending:positionClimate,
    dropOut,resid) %>% 
  distinct() 
s <- summary_table(group_by(o,dropOut),summary) %>%
  data.frame()
pVals <- c(
  dataRhymeAndReasonExt_withDropOuts %$% 
    round(t.test(age~dropOut)$p.value,2),"","", 
    dataRhymeAndReasonExt_withDropOuts %>% 
    filter(gender=='Female'|gender=='Male') %$% 
    round(chisq.test(gender,dropOut)$p.value,2),"","",
  dataRhymeAndReasonExt_withDropOuts %>% filter(!is.na(edu)) %$% 
    round(chisq.test(edu,dropOut)$p.value),"","","","","","",
  dataRhymeAndReasonExt_withDropOuts %>% 
    filter(!is.na(urban_rural)) %$% 
    round(chisq.test(urban_rural,dropOut)$p.value,2),"","","","","",
  dataRhymeAndReasonExt_withDropOuts %>% 
    filter(!is.na(positionSocialSpending)) %$% 
    round(chisq.test(positionSocialSpending,dropOut)$p.value,2),"",
  dataRhymeAndReasonExt_withDropOuts %>% 
    filter(!is.na(positionTiesEU)) %$% 
    round(chisq.test(positionTiesEU,dropOut)$p.value,2),"",
  dataRhymeAndReasonExt_withDropOuts %>% 
    filter(!is.na(positionImmigration)) %$% 
    round(chisq.test(positionImmigration,dropOut)$p.value,2),"",
  dataRhymeAndReasonExt_withDropOuts %>% 
    filter(!is.na(positionClimate)) %$% 
    round(chisq.test(positionClimate,dropOut)$p.value,2),"")
n <- o %>% group_by(dropOut) %>% summarise(N=n()) %>% pull(N)
t <- rbind(c("","",paste("(N=",n,")",sep=''),""),cbind(c,row.names(s),s,pVals))
p <- xtable(t)
names(p) <- c("","",
              "Dropped out",
              "Finished",
              "p-value")

print(xtable(p,type='latex',align="rrllll"),file='tableB4.tex',
  include.rownames=F,floating=F,sanitize.text.function= function(x){x})

#_____________________________________________________________________________#
#_____________________________________________________________________________#
# C  Statistical appendix ----
#_____________________________________________________________________________#
# C.1  Summary statistics ----
#_____________________________________________________________________________#
# Figure C.4: ----
# Distribution of outcome variables every MP like this MP and feeling 
# represented by country in the first experiment.
#_____________________________________________________________________________#
pdf('figureC4.pdf',height=6)
dataRhymeAndReason %>% pivot_longer(cols=c(feel.represented,like.this.mp),
  names_to='outcomeVariable',values_to='outcomeValues') %>%
  mutate(outcomeVariable=recode(outcomeVariable,
    'feel.represented'='Feeling represented',
    'like.this.mp'='Every MP like this MP')) %>%
  group_by(country,outcomeVariable,outcomeValues) %>%
  summarise(n=n()) %>% mutate(N=max(cumsum(n)),prop=n/N) %>%
  ggplot(aes(y=prop,x=outcomeValues)) +
  facet_grid(country~outcomeVariable) +    
  geom_col(color='black') +
  scale_x_continuous(breaks=seq(1,7,1)) +
  labs(y='Relative frequency',x='') +
  theme_bw() +
  theme(axis.text.x=element_text(angle=45,hjust=1))
dev.off()

#_____________________________________________________________________________#
# Figure C.5: ----
# Distribution of outcome variables every MP like this MP, feeling represented, 
# as your MP in the second experiment (UK only).
#_____________________________________________________________________________#
pdf('figureC5.pdf',height=3)
dataRhymeAndReasonExt %>% 
  pivot_longer(cols=c(feelingRepresented,likeThisMP),
    names_to='outcomeVariable',values_to='outcomeValues') %>% 
  mutate(
    outcomeVariable=recode(ifelse(treatment=='Alternative outcome','asYourMP',
      outcomeVariable),
      'feelRepresented'='Feeling represented',
      'likeThisMP'='Every MP like this MP',
      'asYourMP'="As your MP")) %>%
  group_by(outcomeVariable,outcomeValues) %>%
  summarise(n=n()) %>% mutate(N=max(cumsum(n)),prop=n/N) %>%
  ggplot(aes(y=prop,x=outcomeValues)) +
  facet_grid(~outcomeVariable) +    
  geom_col(color='black') +
  scale_x_continuous(breaks=seq(1,7,1)) +
  labs(y='Relative frequency',x='') +
  theme_bw() +
  theme(axis.text.x=element_text(angle=45,hjust=1))
dev.off()

#_____________________________________________________________________________#
# C.2  Regression tables ----
#_____________________________________________________________________________#
# Table C.5: ----
# Regression of outcome measures on rebel status. Standard errors clustered at 
# the respondent-level.
#_____________________________________________________________________________#
m1 <- dataRhymeAndReason %>% 
  lm_robust(feel.represented~rebel,data=.,clusters=resid)
m2 <- dataRhymeAndReason %>% 
  lm_robust(like.this.mp~rebel,data=.,clusters=resid)

texreg(list(m1,m2),digits=3, single.row=F, include.ci=F, stars=c(.1,.05,.01),
custom.model.name=c('Every MP like this MP','Feeling represented'),
reorder.coef=c(2,1),
custom.coef.names=c('Constant','Rebel'),
caption="Regression of outcome measures on rebel status. Standard errors clustered at the
respondent-level.",caption.above=T,table=F,file='tableC5.tex') 

#_____________________________________________________________________________#
# Tables C.6 and C.7: ----
# Regression of outcome measures on rebel status, indicator of treatment, and
# interaction of the two variables. Standard errors clustered at the 
# respondent-level.
#_____________________________________________________________________________#
out <- dataRhymeAndReason %>% 
  filter(treatment=='Baseline'|treatment=='Against public') %>% 
  droplevels() %>% 
  mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline','Against public'),
    levels=c('Baseline','Against public')))

m1 <- out %>% 
  lm_robust(feel.represented~rebel*treatment,clusters=resid,data=.)
m2 <- out %>% 
  lm_robust(like.this.mp~rebel*treatment,clusters=resid,data=.)

out <- dataRhymeAndReason %>% 
  filter(treatment=='Baseline'|treatment=='With public') %>% 
  droplevels() %>% 
  mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline','With public'),
    levels=c('Baseline','With public')))

m3 <- out %>% 
  lm_robust(feel.represented~rebel*treatment,clusters=resid,data=.)
m4 <- out %>% 
  lm_robust(like.this.mp~rebel*treatment,clusters=resid,data=.)

out <- dataRhymeAndReason %>% 
  filter(treatment=='Baseline'|treatment=='Against voter') %>% 
  droplevels() %>% 
  mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline','Against voter'),
    levels=c('Baseline','Against voter')))

m5 <- out %>% 
  lm_robust(feel.represented~rebel*treatment,clusters=resid,data=.)
m6 <- out %>% 
  lm_robust(like.this.mp~rebel*treatment,clusters=resid,data=.)

out <- dataRhymeAndReason %>% 
  filter(treatment=='Baseline'|treatment=='With voter') %>% 
  droplevels() %>% 
  mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline','With voter'),
    levels=c('Baseline','With voter')))

m7 <- out %>% 
  lm_robust(feel.represented~rebel*treatment,clusters=resid,data=.)
m8 <- out %>% 
  lm_robust(like.this.mp~rebel*treatment,clusters=resid,data=.)

texreg(list(m1,m2,m3,m4),digits=3, single.row=F, include.ci=F, stars=c(.1,.05,.01),
custom.model.name=c('Every MP like\nthis MP','Feeling\nrepresented',
'Every MP like\nthis MP','Feeling\nrepresented'),
reorder.coef=c(2,3,4,5,6,1),
custom.coef.names=c('Constant','Rebel','Against public','With public',
'Rebel × Against public','Rebel × With public'),
caption="Regression of outcome measures on rebel status, indicator of treatment, and the
interaction of the two variables. Standard errors clustered at the respondent-level.",
caption.above=T,table=F,file='tableC6.tex') 

texreg(list(m5,m6,m7,m8),digits=3, single.row=F, include.ci=F, stars=c(.1,.05,.01),
custom.model.name=c('Every MP like this MP','Feeling represented',
'Every MP like this MP','Feeling represented'),
reorder.coef=c(2,3,4,5,6,1),
custom.coef.names=c('Constant','Rebel','Against voter','With voter',
'Rebel × Against voter','Rebel × With voter'),
caption="Regression of outcome measures on rebel status, indicator of treatment, and the
interaction of the two variables. Standard errors clustered at the respondent-level.",
caption.above=T,table=F,file='tableC7.tex') 

#_____________________________________________________________________________#
# Table C.8 and C.9: ----
# Regression of indicator whether a characteristic is mentioned considering the 
# fifth vignette on rebel status, vignette order, issue of the bill, and country 
# fixed-effects. Standard errors clustered at the respondent-level.
#_____________________________________________________________________________#
var.list <- c('independent','honest','strong.convictions','defends.interest.voters',
              'willing.to.compromise','decisive','loyal.to.party','cowardly',
              'disrespectful','irresponsible','selfish','unreliable',
              'untrustworthy','stupid')

m <- dataRhymeAndReason %>% 
  filter(vignette==5) %>%
  select(resid,feel.represented,like.this.mp,rebel,treatment,var.list,bill,country) %>%
  pivot_longer(cols=unlist(var.list),names_to='variable') %>%
  mutate(variable=factor(variable,levels=c('independent','honest',
    'strong.convictions','defends.interest.voters','willing.to.compromise',
    'decisive','loyal.to.party','cowardly','disrespectful','irresponsible',
    'selfish','unreliable','untrustworthy','stupid'))) %>%
  group_by(variable) %>%
  do(m=lm_robust(value~rebel,data=.)) 

texreg(list(m$m[[1]],m$m[[2]],m$m[[3]],m$m[[4]],m$m[[5]],m$m[[6]],m$m[[7]]),
digits=3, single.row=F, include.ci=F, stars=c(.1,.05,.01),
custom.model.names=c('Independent','Honest','Strong personal convictions',
'Defends interest of his/her voters','Willing to compromise','Decisive',
'Loyal to party'),
reorder.coef=c(2,1),
custom.coef.names=c('Constant','Rebel'),
caption="Regression of indicator whether a characteristic is mentioned considering the fifth
vignette on rebel status. Standard errors clustered at the respondent-level.",
caption.above=T,table=F,file='tableC8.tex') 

texreg(list(m$m[[8]],m$m[[9]],m$m[[10]],m$m[[11]],m$m[[12]],m$m[[13]],
m$m[[14]]),digits=3, single.row=F, include.ci=F, stars=c(.1,.05,.01),
custom.model.names=c('Cowardly','Disrespectful','Irresponsible','Selfish',
'Unreliable','Untrustworthy','Stupid'),
reorder.coef=c(2,1),
custom.coef.names=c('Constant','Rebel'),
caption="Regression of indicator whether a characteristic is mentioned considering the fifth
vignette on rebel status. Standard errors clustered at the respondent-level.",
caption.above=T,table=F,file='tableC9.tex') 

#_____________________________________________________________________________#
# Table C.10 ----
# Regression of outcome measures on rebel status and vignette number 
# for vignettes 1 and 2 in the baseline. Standard errors clustered at the 
# respondent-level.
#_____________________________________________________________________________#
m1 <- dataRhymeAndReasonExt %>% 
  filter(baseline=='Baseline') %>%
  mutate(vignette=factor(vignette)) %>%
  lm_robust(feelingRepresented~rebel*vignette,data=.,clusters=resid)
m2 <- dataRhymeAndReasonExt %>% 
  filter(baseline=='Baseline') %>%
  mutate(vignette=factor(vignette)) %>%
  lm_robust(likeThisMP~rebel*vignette,data=.,clusters=resid)

texreg(list(m1,m2),digits=3, single.row=F, include.ci=F,stars=c(.1,.05,.01),
custom.model.names=c('Every MP like this MP','Feeling represented'),
reorder.coef=c(2,3,4,5,6,1),
custom.coef.names=c('Constant','Rebel','Vignette 2','Vignette 3','Rebel x Vignette 2',
'Rebel x Vignette 3'),
caption="Regression of indicator whether a characteristic is mentioned considering the fifth
vignette on rebel status. Standard errors clustered at the respondent-level.",
caption.above=T,table=F,file='tableC10.tex') 

#_____________________________________________________________________________#
# Table C.11 ----
# Regression of indicator whether respondent associated being independent, 
# having strong personal convictions, and being loyal to the party on rebel 
# status and vignette number when associations are elicited. Standard errors 
# clustered at the respondent-level.
#_____________________________________________________________________________#
out <- dataRhymeAndReasonExt %>% 
  filter((treatment=='Characteristics'&vignette==orderCharacteristics)|
  (treatment!='Characteristics'&vignette=='4'))

m1 <- out %>% lm_robust(independent~rebel*as.numeric(vignette),data=.,
  clusters=resid)
m2 <- out %>% lm_robust(strongConvictions~rebel*as.numeric(vignette),data=.,
  clusters=resid)
m3 <- out %>% lm_robust(loyalToParty~rebel*as.numeric(vignette),data=.,
  clusters=resid)

texreg(list(m1,m2,m3),digits=3, single.row=F, include.ci=F,stars=c(.1,.05,.01),
custom.model.names=c('Independent','Strong personal convictions','Being loyal'),
reorder.coef=c(2,3,4,1),
custom.coef.names=c('Constant','Rebel','Vignette number','Rebel x Vignette number'),
caption="Regression of indicator whether respondent associated being independent, having strong personal convictions, and being loyal to the party on rebel status and vignette number when associations are elicited. Standard errors clustered at the respondent-level.",
caption.above=T,table=F,file='tableC11.tex') 

#_____________________________________________________________________________#
# C.3  Robustness of main results ----
#_____________________________________________________________________________#
# Figure C.6 ----
# Difference between total rebel effect 𝜏 (Rebel) and rebel effect when 
# respondents learn that the MP shares their policy positions, 𝜏 (Rebel | 
# Congruent with voter), does not share their policy positions 𝜏 (Rebel | 
# Not congruent with voter), shares the public’s policy positions, 𝜏 (Rebel | 
# Congruent with public), does not share the public’s policy position 𝜏 (Rebel | 
# Not congruent with public), as well as the same quantities pooling the treatments
# with voter and with voter-against public, with public and against voter-with 
# public, against voter and against voter-with public, and against public and 
# with voter-against public. 
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
out <- dataRhymeAndReason %>% 
  select(resid,rebel,vignette,bill,treatment,feel.represented,like.this.mp,
    country) %>% 
  gather(variable,value,feel.represented:like.this.mp) 

results <- rbind(
  out %>% filter(treatment=='Baseline'|treatment=='With voter') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','With voter')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentWith voter') %>%
    mutate(term=str_sub(term,21,-1)),
  out %>% filter(treatment=='Baseline'|treatment=='Against voter') %>% 
    droplevels() %>% 
    mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline',
      'Against voter'),levels=c('Baseline','Against voter'))) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
      clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentAgainst voter') %>%
    mutate(term=str_sub(term,21,-1)),
  out %>% filter(treatment=='Baseline'|treatment=='With public') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','With public')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
      clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentWith public') %>%
    mutate(term=str_sub(term,21,-1)),
  out %>% filter(treatment=='Baseline'|treatment=='Against public') %>% 
    droplevels() %>% 
    mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline',
      'Against public'),levels=c('Baseline','Against public'))) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentAgainst public') %>%
    mutate(term=str_sub(term,21,-1)),
  out %>% filter(treatment=='Baseline'|treatment=='With voter'|
      treatment=='With voter-Against public') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','With voter')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentWith voter') %>%
    mutate(term=paste(str_sub(term,21,-1),' broadly defined',sep='')),
  out %>% filter(treatment=='Baseline'|treatment=='Against voter'|
      treatment=='Against voter-With public') %>% 
    droplevels() %>% 
    mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline',
      'Against voter'),levels=c('Baseline','Against voter'))) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentAgainst voter') %>%
    mutate(term=paste(str_sub(term,21,-1),' broadly defined',sep='')),
  out %>% filter(treatment=='Baseline'|treatment=='With public'|
                   treatment=='Against voter-With public') %>% 
    droplevels() %>% 
    mutate(treatment=ifelse(treatment=='Baseline','Baseline','With public')) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment + vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentWith public') %>%
    mutate(term=paste(str_sub(term,21,-1),' broadly defined',sep='')),
  out %>% filter(treatment=='Baseline'|treatment=='Against public'|
                   treatment=='With voter-Against public') %>% 
    droplevels() %>% 
    mutate(treatment=factor(ifelse(treatment=='Baseline','Baseline',
      'Against public'),levels=c('Baseline','Against public'))) %>% 
    group_by(variable) %>%
    do(lm_robust(value~rebel*treatment+ vignette + bill + country,
                 clusters=resid,data=.) %>% tidy()) %>% 
    filter(term=='rebelRebel:treatmentAgainst public') %>%
    mutate(term=paste(str_sub(term,21,-1),' broadly defined',sep='')))

pdf('figureC6.pdf', height=3)
results %>%
  mutate(l2=estimate-1.6*std.error,u2=estimate+1.6*std.error,
    variable=ifelse(variable=='feel.represented'|
      variable=='feel.represented.baseline','Feel represented',
      'Every MP like this MP')) %>%
  ggplot(aes(x=term,y=estimate,ymin=conf.low,ymax=conf.high)) +
  facet_grid(~variable) +
  geom_pointrange(size=.2,shape=19) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),linewidth=1,size=.2,shape=19) +
  geom_hline(yintercept=0,color='gray') +
  coord_flip() + 
  scale_y_continuous(limits=c(-.17,.17)) +
  labs(y='Eliminated effect',x='') +
  theme_bw()
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure C.7: ---- 
# AMCE on outcome measures feeling represented and every MP like this MP for all 
# attributes by authoritarian values (Panel A), populist attitudes (Panel B), 
# and trust in government (Panel C).
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
out <- dataRhymeAndReason %>% 
  mutate(vignette=factor(vignette),
    highAuthoritarian=ifelse(authoritarian>median(authoritarian,na.rm=T),
        'High authoritarian values','Low authoritarian values'),
    highPopulist=ifelse(populist>median(populist,na.rm=T),
        'Strong populist attitudes','Weak populist attitudes'),
    lowTrust=ifelse(trustGovernment<median(trustGovernment,na.rm=T),
        'Low trust in government','High trust in government'),
    lowInterest=ifelse(interestPolitics<median(interestPolitics,na.rm=T),
        'Low interest in politics','High interest in politics'))

results <- rbind(
  out %>% group_by(highAuthoritarian) %>%
    do(cj(.,feel.represented ~ bill + outcome + margin + gender + party + 
      term + rebel + vignette + country + bill, id= ~ resid, estimate='amce')) %>% 
    mutate(variable='Feeling represented') %>% rename(grouping=highAuthoritarian),
  out %>% group_by(highAuthoritarian) %>%
    do(cj(.,like.this.mp ~ bill + outcome + margin + gender + party + 
      term + rebel + vignette + country + bill, id= ~ resid, estimate='amce')) %>% 
    mutate(variable='Every MP like this MP') %>% rename(grouping=highAuthoritarian),
  out %>% group_by(highPopulist) %>%
    do(cj(.,feel.represented ~ bill + outcome + margin + gender + party + 
      term + rebel + vignette + country + bill, id= ~ resid, estimate='amce')) %>% 
    mutate(variable='Feeling represented') %>% rename(grouping=highPopulist),
  out %>% group_by(highPopulist) %>%
    do(cj(.,like.this.mp ~ bill + outcome + margin + gender + party + 
      term + rebel + vignette + country + bill, id= ~ resid, estimate='amce')) %>% 
    mutate(variable='Every MP like this MP') %>% rename(grouping=highPopulist),
  out %>% group_by(lowTrust) %>%
    do(cj(.,feel.represented ~ bill + outcome + margin + gender + party + 
      term + rebel + vignette + country + bill, id= ~ resid, estimate='amce')) %>% 
    mutate(variable='Feeling represented') %>% rename(grouping=lowTrust),
  out %>% group_by(lowTrust) %>%
    do(cj(.,like.this.mp ~ bill + outcome + margin + gender + party + 
      term + rebel + vignette + country + bill, id= ~ resid, estimate='amce')) %>% 
    mutate(variable='Every MP like this MP') %>% rename(grouping=lowTrust),
  out %>% group_by(lowInterest) %>%
    do(cj(.,feel.represented ~ bill + outcome + margin + gender + party + 
      term + rebel + vignette + country + bill, id= ~ resid, estimate='amce')) %>% 
    mutate(variable='Feeling represented') %>% rename(grouping=lowInterest),
  out %>% group_by(lowInterest) %>%
    do(cj(.,like.this.mp ~ bill + outcome + margin + gender + party + 
      term + rebel + vignette + country + bill, id= ~ resid, estimate='amce')) %>% 
    mutate(variable='Every MP like this MP') %>% rename(grouping=lowInterest))

pdf('figureC7.pdf',height=3)
results %>% filter(level=='Rebel'&!is.na(grouping)) %>%
  droplevels() %>%
  mutate(
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error,
    grouping=factor(grouping,
      levels=c('High trust in government',
        'Low trust in government',
        'Weak populist attitudes',
        'Strong populist attitudes',
        'Low authoritarian values',
        'High authoritarian values',
        'Low interest in politics',
        'High interest in politics'))) %>%
  ggplot(aes(x=grouping,y=estimate,ymin=lower,ymax=upper)) +
  facet_grid(~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(size=.3,shape=19) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),linewidth=1,size=.3,shape=19) +
  coord_flip() + 
  labs(x='',y='AMCE (Rebel)') +
  guides(fill=guide_legend(ncol=4)) +
  theme_bw() +
  theme(legend.position='none')
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure C.8: ---- 
# AMCE on outcome measures feeling represented and every MP like this MP for 
# all attributes and by bill.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
amce.feel.rep <- 
  cj(dataRhymeAndReason,feel.represented ~ outcome + margin + gender + 
       party + term + rebel, id=~resid, estimate='amce', by=~bill) %>% 
  mutate(variable='Feeling represented')
amce.like.MP <- 
  cj(dataRhymeAndReason,like.this.mp ~ outcome + margin + gender + 
       party + term + rebel, id= ~ resid, estimate='amce', by=~bill) %>% 
  mutate(variable='Every MP like this MP')
amce <- rbind(amce.feel.rep,amce.like.MP) 

pdf('figureC8.pdf',height=8)
amce %>% 
  mutate(
    baseline=ifelse(estimate==0,'Baseline','Effect'),
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=level,y=estimate,ymin=lower,ymax=upper,color=baseline,
    fill=baseline)) +
  facet_grid(bill~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(position=position_dodge(width=.6),size=.3,shape=19) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.6),
    linewidth=1,size=.3,shape=19) +
  coord_flip() + 
  scale_color_manual(values=c('gray','black')) + 
  scale_fill_manual(values=c('gray','black')) + 
  labs(x='',y='AMCE') +
  guides(fill=guide_legend(ncol=4)) +
  theme_bw() +
  theme(legend.position='none',
    axis.text.y=element_text(color=c('gray',rep('black',4),'gray','black',
    'gray','black','gray','black','gray','black','gray','black')))
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure C.9: ---- 
# AMCE on outcome measures feeling represented and every MP like this MP for 
# all attributes and by country.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
amce.feel.rep <- 
  cj(dataRhymeAndReason,feel.represented ~ bill + outcome + margin + gender + 
       party + term + rebel, id=~resid, estimate='amce', by=~country) %>% 
  mutate(variable='Feeling represented')
amce.like.MP <- 
  cj(dataRhymeAndReason,like.this.mp ~ bill + outcome + margin + gender + 
       party + term + rebel, id= ~ resid, estimate='amce', by=~country) %>% 
  mutate(variable='Every MP like this MP')
amce <- rbind(amce.feel.rep,amce.like.MP) 

pdf('figureC9.pdf',height=8)
amce %>% 
  mutate(
    baseline=ifelse(estimate==0,'Baseline','Effect'),
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=level,y=estimate,ymin=lower,ymax=upper,color=baseline,
    fill=baseline)) +
  facet_grid(country~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(position=position_dodge(width=.6),size=.3,shape=19) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.6),
    linewidth=1,size=.3,shape=19) +
  coord_flip() + 
  scale_color_manual(values=c('gray','black')) + 
  scale_fill_manual(values=c('gray','black')) + 
  labs(x='',y='AMCE') +
  guides(fill=guide_legend(ncol=4)) +
  theme_bw() +
  theme(
    legend.position='none',text=element_text(size=10),
    axis.text.y=element_text(color=c('gray',rep('black',4),'gray','black',
    'gray','black','gray','black','gray','black','gray','black')))
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure C.10/11: ---- 
# AMCE on outcome variables feeling represented and be like this MP by attribute
# and congruence treatment.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
amce.feel.rep <- 
  cj(dataRhymeAndReason,feel.represented ~ bill + outcome + margin + gender + 
       party + term + rebel, id=~resid, estimate='amce', by=~treatment) %>% 
  mutate(variable='Feeling represented')
amce.like.MP <- 
  cj(dataRhymeAndReason,like.this.mp ~ bill + outcome + margin + gender + 
       party + term + rebel, id= ~ resid, estimate='amce', by=~treatment) %>% 
  mutate(variable='Every MP like this MP')
amce <- rbind(amce.feel.rep,amce.like.MP) %>%
  mutate(treatment=factor(treatment,
    levels=c('Against voter','With voter',
      'Against public','With public',
      'Against voter-With public',
      'With voter-Against public',
      'Baseline'))) 

pdf('figureC10.pdf',height=10)
amce %>% filter(treatment=='Baseline'|treatment=='Against voter'|
  treatment=='With voter'|treatment=='Against public'|
  treatment=='With public') %>%
  droplevels() %>%
  mutate(
    baseline=ifelse(estimate==0,'Baseline','Effect'),
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=level,y=estimate,ymin=lower,ymax=upper,color=baseline,
             fill=baseline)) +
  facet_grid(treatment~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(position=position_dodge(width=.6),size=.3,shape=19) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.6),
    linewidth=1,size=.3,shape=19) +
  coord_flip() + 
  scale_color_manual(values=c('gray','black')) + 
  scale_fill_manual(values=c('gray','black')) + 
  labs(x='',y='AMCE') +
  guides(fill=guide_legend(ncol=4)) +
  theme_bw() +
  theme(legend.position='none',text = element_text(size=10),
    axis.text.y=element_text(color=c('gray',rep('black',4),'gray','black',
    'gray','black','gray','black','gray','black','gray','black')))
dev.off()

pdf('figureC11.pdf',width=5)
amce %>% filter(treatment=='Baseline'|treatment=='Against voter-With public'|
  treatment=='With voter-Against public') %>%
  droplevels() %>%
  mutate(
    baseline=ifelse(estimate==0,'Baseline','Effect'),
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=level,y=estimate,ymin=lower,ymax=upper,color=baseline,
    fill=baseline)) +
  facet_grid(treatment~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(position=position_dodge(width=.6),size=.3,shape=19) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.6),
    linewidth=1,size=.3,shape=19) +
  coord_flip() + 
  scale_color_manual(values=c('gray','black')) + 
  scale_fill_manual(values=c('gray','black')) + 
  labs(x='',y='AMCE') +
  guides(fill=guide_legend(ncol=4)) +
  theme_bw() +
  theme(legend.position='none',text = element_text(size=10),
    axis.text.y=element_text(color=c('gray',rep('black',4),'gray','black',
    'gray','black','gray','black','gray','black','gray','black')))
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure C.12: ---- 
# AMCE on outcome variables feeling represented and be like this MP for rebel
# vs not rebel 
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o1 <- dataRhymeAndReason
for (i in unique(o1$resid)){
  for (j in 1:5){
    o1$numberRebelsPast[o1$resid==i&o1$vignette==j] = 
      sum(ifelse(o1$resid==i&o1$vignette<j&o1$rebel=='Rebel',1,0)) 
  }
}

o2 <- o1 %>% mutate(numberRebelsPast=factor(numberRebelsPast))
r <- rbind(
  o2 %>% filter(vignette==2) %>% droplevels() %>%
    cj(.,feel.represented ~ rebel, id=~resid, estimate='amce', by=~numberRebelsPast) %>% 
    mutate(variable='Feeling represented',vignette=2),
  o2 %>% filter(vignette==3) %>% droplevels() %>%
    cj(.,feel.represented ~ rebel, id=~resid, estimate='amce', by=~numberRebelsPast) %>% 
    mutate(variable='Feeling represented',vignette=3),
  o2 %>% filter(vignette==4) %>% droplevels() %>%
    cj(.,feel.represented ~ rebel, id=~resid, estimate='amce', by=~numberRebelsPast) %>% 
    mutate(variable='Feeling represented',vignette=4),
  o2 %>% filter(vignette==5) %>% droplevels() %>%
    cj(.,feel.represented ~ rebel, id=~resid, estimate='amce', by=~numberRebelsPast) %>% 
    mutate(variable='Feeling represented',vignette=5),
  o2 %>% filter(vignette==2) %>% droplevels() %>%
    cj(.,like.this.mp ~ rebel, id=~resid, estimate='amce', by=~numberRebelsPast) %>% 
    mutate(variable='Every MP like this MP',vignette=2),
  o2 %>% filter(vignette==3) %>% droplevels() %>%
    cj(.,like.this.mp ~ rebel, id=~resid, estimate='amce', by=~numberRebelsPast) %>% 
    mutate(variable='Every MP like this MP',vignette=3),
  o2 %>% filter(vignette==4) %>% droplevels() %>%
    cj(.,like.this.mp ~ rebel, id=~resid, estimate='amce', by=~numberRebelsPast) %>% 
    mutate(variable='Every MP like this MP',vignette=4),
  o2 %>% filter(vignette==5) %>% droplevels() %>%
    cj(.,like.this.mp ~ rebel, id=~resid, estimate='amce', by=~numberRebelsPast) %>% 
    mutate(variable='Every MP like this MP',vignette=5))

p <-r %>% 
  filter(level=='Rebel') %>%
  mutate(l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>% 
  ggplot(aes(x=level,y=estimate,ymin=lower,ymax=upper,color=numberRebelsPast,
             fill=numberRebelsPast)) +
  facet_grid(vignette~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(position=position_dodge(width=.6),shape=21) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.6),
                  shape=21,linewidth=1) +
  coord_flip() + 
  scale_color_manual(values=c('gray','black','steelblue1','steelblue3','blue')) + 
  scale_fill_manual(values=c('gray','black','steelblue1','steelblue3','blue')) + 
  labs(x='',y='AMCE') +
  guides(color=guide_legend(ncol=4,title='Number of past rebels'),
         fill=guide_legend(ncol=4,title='Number of past rebels')) +
  theme_bw() +
  theme(legend.position='bottom',
        axis.text.y=element_blank(),axis.ticks.y=element_blank())

pdf('figureC12.pdf',height=4)
grid.arrange(p,right='Vignette number             ')
dev.off() 

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure C.13: ---- 
# AMCE on outcome variables feeling represented and be like this MP for rebel
# vs not rebel by senior vs junior coalition partner in Germany
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
o <- dataRhymeAndReason %>%
  mutate(
    seniorCoalition=factor(ifelse(
      voteChoice=='CDU/CSU'|voteChoice=='Conservative'|
        voteChoice=='La République en Marche','Senior coalition party',
      ifelse(
        voteChoice=='SPD'|voteChoice=='Movimento 5 Stelle'|
          voteChoice=='Lega'|q15_other=='Mouvement démocrate',
        'Junior coalition party',NA)))) %>%
  droplevels() %>%
  filter(country=='Germany')

r <- rbind(
  cj(o,feel.represented ~ rebel, id=~resid, estimate='amce', by=~seniorCoalition) %>% 
    mutate(variable='Feeling represented'),
  cj(o,like.this.mp ~ rebel, id= ~ resid, estimate='amce', by=~seniorCoalition) %>% 
    mutate(variable='Every MP like this MP'))

pdf('figureC13.pdf',height=3)
r %>% 
  filter(level=='Rebel') %>%
  mutate(l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=level,y=estimate,ymin=lower,ymax=upper,color=seniorCoalition,
             fill=seniorCoalition)) +
  facet_grid(~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  geom_pointrange(position=position_dodge(width=.6),shape=21) + 
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.6),
                  linewidth=1,shape=21) +
  coord_flip() + 
  scale_color_manual(values=c('gray','black')) + 
  scale_fill_manual(values=c('gray','black')) + 
  labs(x='',y='AMCE') +
  guides(fill=guide_legend(ncol=4)) +
  theme_bw() +
  theme(legend.position='bottom',legend.title=element_blank(),
        axis.text.y=element_blank(),axis.ticks.y=element_blank())
dev.off()

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++#
# Figure C.14: ---- 
## Effect of rebellion (Panel A) and effect of respondent-level bias 
# towards rebels (Panel B) on whether respondents attribute a character trait 
# to the MP (MP traits).
#_____________________________________________________________________________#
var.list <- c('independent','loyal.to.party','honest','strong.convictions',
  'defends.interest.voters','willing.to.compromise','untrustworthy',
  'selfish','disrespectful','decisive','irresponsible','cowardly',
  'unreliable','stupid')

out <- dataRhymeAndReason %>%
  group_by(resid,rebel) %>% 
  summarise(feel=mean(feel.represented,na.rm=T),
            like=mean(like.this.mp,na.rm=T)) %>%
  mutate(biasFeel=mean(feel-lag(feel),na.rm=T),
         biasLike=mean(like-lag(like),na.rm=T)) %>%
  filter(!is.na(biasFeel)) %>%
  left_join(dataRhymeAndReason %>% filter(vignette==5) %>%
    pivot_longer(cols=unlist(var.list),names_to='variable') %>%
    select(resid,variable,value,rebel,bill,country)) %>%
  filter(!is.na(value)&rebel=='Rebel')

pdf('figureC14.pdf',height=3)
rbind(
  out %>% group_by(variable) %>%
    do(tidy(lm_robust(value~biasFeel+bill+country,data=.))) %>%
    filter(term=='biasFeel') %>% mutate(outcome='Feel represented'),
  out %>% group_by(variable) %>%
    do(tidy(lm_robust(value~biasLike+bill+country,data=.))) %>%
    filter(term=='biasLike') %>% mutate(outcome='Every MP like this MP')) %>%
  mutate(lower=conf.low,upper=conf.high,
    l2=estimate-1.6*std.error,u2=estimate+1.6*std.error,
    variable=factor(recode(variable,'independent'='Independent',
      'honest'='Honest','strong.convictions'='Strong personal convictions',
      'defends.interest.voters'='Defends interest of his/her voters',
      'willing.to.compromise'='Willing to compromise',
      'loyal.to.party'='Loyal to party','decisive'='Decisive',
      'stupid'='Stupid','cowardly'='Cowardly',
      'disrespectful'='Disrespectful','irresponsible'='Irresponsible',
      'selfish'='Selfish','unreliable'='Unreliable',
      'untrustworthy'='Untrustworthy'),
      levels=c('Stupid','Untrustworthy','Unreliable','Selfish',
        'Irresponsible','Disrespectful','Cowardly','Decisive',
        'Loyal to party','Willing to compromise',
        'Defends interest of his/her voters',
        'Strong personal convictions','Honest','Independent'))) %>%
  ggplot(aes(x=variable,y=estimate,ymin=lower,ymax=upper,
    color=outcome,fill=outcome)) +
  geom_pointrange(position=position_dodge(width=.5),size=.3,shape=21) +
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.5),
    size=.3,linewidth=1,shape=21) +
  geom_hline(yintercept=0,color='gray') +
  coord_flip() + 
  scale_y_continuous() +
  scale_color_manual(values=c('gray','black')) +
  scale_fill_manual(values=c('gray','black')) +
  guides(color=guide_legend(ncol=1),fill=guide_legend(ncol=1)) +
  labs(y='Effect of bias towards rebels on\nprobability of attributing to character trait',x='') +
  theme_bw() +
  theme(legend.title=element_blank(),legend.position='bottom',
        axis.title.x = element_text(size=8))
dev.off()

#_____________________________________________________________________________#
# C.4 Additional analysis of follow-up experiment ----
#_____________________________________________________________________________#
# Figure C.15 ----
#_____________________________________________________________________________#
out1 <-
  dataRhymeAndReasonExt %>%
  mutate(treatmentVignette=factor(paste(treatment,'_',vignette,sep=''))) %>%
  filter(baseline=='Baseline'|treatment=='Alternative outcome') %>% droplevels()

amce1 <- cj(out1,feelingRepresented~rebel, id=~resid, by = ~treatmentVignette, 
    estimate='amce') %>% mutate(variable='Feeling represented') %>%
  rbind(cj(out1,likeThisMP ~ rebel, id= ~resid, by = ~treatmentVignette, 
    estimate='amce') %>% mutate(variable='Every MP like this MP/As your MP')) 
 
out2 <-
  dataRhymeAndReasonExt %>%
  mutate(treatmentVignette=factor(paste(treatment,'_',vignette,sep=''))) %>%
  filter(treatment=='Paired vignette first'&!is.na(pair)) %>% droplevels()

amce2 <- cj(out2,feelingRepresented~rebel, id=~pair, by = ~treatmentVignette, 
    estimate='amce') %>% mutate(variable='Feeling represented') %>%
  rbind(cj(out2,likeThisMP ~ rebel, id= ~pair, by = ~treatmentVignette, 
    estimate='amce') %>% mutate(variable='Every MP like this MP/As your MP')) 

amce <- rbind(amce1,amce2) %>%
  mutate(vignette=factor(str_sub(treatmentVignette,-1,-1),levels=c('4','3','2','1')),
  treatment=factor(recode(str_sub(treatmentVignette,1,-3),
    'Baseline/Distraction'='Baseline','Paired vignette first'='Paired vignette'),
    levels=c('Baseline','Alternative outcome','Paired vignette')),
  l2=estimate-1.6*std.error, u2=estimate+1.6*std.error) %>%
  filter(!is.na(treatment)) %>%
  droplevels()

pdf('figureC15.pdf',height=3)
amce %>% filter(level=='Rebelled') %>%
  ggplot(aes(x=treatment,y=estimate,ymin=lower,ymax=upper,
    color=vignette,fill=vignette)) +
  geom_pointrange(position=position_dodge2(width=.6),size=.3,shape=21) +
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge2(width=.6),
    linewidth=1,size=.3,shape=21) +
  coord_flip() + 
  facet_grid(~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  labs(x='',y='AMCE (Rebel)') +
  guides(fill=guide_legend(ncol=4)) +
  scale_color_manual(values=c('black','black','grey40','grey40')) + 
  scale_fill_manual(values=c('black','white','grey40','white')) +
  theme_bw() +
  theme(legend.position='bottom',legend.title=element_blank())
dev.off()

#_____________________________________________________________________________#
# Figure C.16: ====
# AMCE of rebel attribute on outcome variables feeling represented and be like 
# this MP by vignette and whether participants expressed positive, neutral, or 
# negative sentiment towards the act of rebellion in the before reminder 
# treatment.
#_____________________________________________________________________________#
out <- dataRhymeAndReasonExt %>% 
  filter(v1IntroCognitiveSentiment!=-99&!is.na(v1IntroCognitiveSentiment)) %>%
  mutate(cogSent=factor(recode(v1IntroCognitiveSentiment,
    `-1`='Negative',`0`='Neutral',`1`='Positive')),
    vignette=factor(vignette))

mm.feel.rep <- 
  cj(out,feelingRepresented~rebel, id= ~resid, by = ~cogSent + vignette, 
     estimate='amce') %>% mutate(variable='Feeling represented')
mm.like.MP <- 
  cj(out,likeThisMP~rebel, id= ~resid, by = ~cogSent + vignette, 
     estimate='amce') %>% mutate(variable='Every MP like this MP')
mm <- rbind(mm.feel.rep,mm.like.MP) %>% filter(!is.na(feature))

pdf('figureC16.pdf',height=3)
mm %>% filter(level=='Rebelled') %>%
  mutate(l2=estimate-1.6*std.error,u2=estimate+1.6*std.error) %>%
  ggplot(aes(x=cogSent,y=estimate,ymin=lower,ymax=upper,
             color=vignette,fill=vignette)) +
  geom_pointrange(position=position_dodge(width=.3),fatten=.5,size=.5,shape=21) +
  geom_pointrange(aes(ymin=l2,ymax=u2),position=position_dodge(width=.3),
                  fatten=.5,size=1,shape=21) +
  coord_flip() + 
  facet_grid(~variable) +
  geom_hline(aes(yintercept=0),color='gray') +
  labs(x='',y='AMCE (Rebel)') +
  guides(fill=guide_legend(ncol=4,title='Vignette'),
         color=guide_legend(ncol=4,title='Vignette')) +
  scale_color_manual(values=c('black','grey40','grey40','grey')) + 
  scale_fill_manual(values=c('black','grey40','white','grey')) +
  theme_bw() +
  theme(legend.position='bottom')
  dev.off()
